-- stack: in -- format: 8 (HyperCard 1) -- flags: 0x1000 (none) -- protect password hash: 0 -- maximum user level: 5 (scripting) -- window: Rect(x1=0, y1=0, x2=0, y2=0) -- screen: Rect(x1=0, y1=0, x2=0, y2=0) -- card dimensions: w=0 h=0 -- scroll: x=0 y=0 -- background count: 1 -- first background id: 2574 -- card count: 2 -- first card id: 3233 -- list block id: 3468 -- print block id: 0 -- font table block id: 0 -- style table block id: 0 -- free block count: 0 -- free size: 0 bytes -- total size: 19744 bytes -- stack block size: 13312 bytes -- created by hypercard version: 0x00000000 -- compacted by hypercard version: 0x01228000 -- modified by hypercard version: 0x01228000 -- opened by hypercard version: 0x01228000 -- patterns[0]: 0x0000000000000000 -- patterns[1]: 0x8000000008000000 -- patterns[2]: 0x8800220088002200 -- patterns[3]: 0x8888222288882222 -- patterns[4]: 0x88AA22AA88AA22AA -- patterns[5]: 0xCCAA33AACCAA33AA -- patterns[6]: 0xEEAABBAAEEAABBAA -- patterns[7]: 0xEEBBBBEEEEBBBBEE -- patterns[8]: 0xFFBBFFEEFFBBFFEE -- patterns[9]: 0xFFBBFFFFFFBBFFFF -- patterns[10]: 0x8010022001084004 -- patterns[11]: 0xFFFFFFFFFFFFFFFF -- patterns[12]: 0x8822882288228822 -- patterns[13]: 0x1122448811224488 -- patterns[14]: 0xC4800C6843023026 -- patterns[15]: 0xB130031BD8C00C8D -- patterns[16]: 0xAA00AA00AA00AA00 -- patterns[17]: 0x8822552288225522 -- patterns[18]: 0x8855225588552255 -- patterns[19]: 0x77DD77DD77DD77DD -- patterns[20]: 0x8000000000000000 -- patterns[21]: 0xAA55AA55AA55AA55 -- patterns[22]: 0x038448300C020101 -- patterns[23]: 0x8244394482010101 -- patterns[24]: 0x8814224188412214 -- patterns[25]: 0x8080413E080814E3 -- patterns[26]: 0x22048C7422179810 -- patterns[27]: 0xBE808808EB088880 -- patterns[28]: 0x25C8328964244C92 -- patterns[29]: 0xA29C41BE2AC914EB -- patterns[30]: 0x40A00000040A0000 -- patterns[31]: 0x8040200002040800 -- patterns[32]: 0xAA00800088008000 -- patterns[33]: 0xFF80808080808080 -- patterns[34]: 0x081C22C180010204 -- patterns[35]: 0xFF808080FF080808 -- patterns[36]: 0xF87422478F172271 -- patterns[37]: 0xBF00BFBFB0B0B0B0 -- patterns[38]: 0xFF7FBE5DA2418000 -- patterns[39]: 0xFAF5FAF5A050A050 -- checksum: 0x0 ----- HyperTalk script ----- on domenu menu --// Added by Medior, Inc. 2/20/90 global RPStackName if menu is in "Home,Quit HyperCard" and RPStackName is not empty then set cursor to watch put RPStackName into shortname repeat until offset(":",shortname) = 0 delete char 1 to offset(":",shortname) of shortname end repeat delete last char of shortname answer "This will return to "&shortname&"." with "Cancel" or "OK" if it is "Cancel" then exit domenu set cursor to watch lock screen go RPStackName unlock screen with dissolve exit domenu else pass doMenu end domenu on openStack defineStruct set the lineSize to 1 set the pattern to 1 show message at 22,300 end openStack on closeStack put empty into message set the pattern to 12 end closeStack on openCard global rootNode, searchPath, pathLength if the number of card fields > 0 then put the id of card field 1 into rootNode else put 0 into rootNode end if put empty into searchPath put 0 into pathLength walkTree end openCard on deleteCard global searchPath, pathLength put empty into searchPath put 0 into pathLength end deleteCard on closeCard undoPlot put empty into field treeList end closeCard on defineStruct global rootRect, rootLoc, hSpacing, vSpacing, rootLevel put "241,148,271,163" into rootRect put "256,155" into rootLoc put "16,32,64,128" into hSpacing put "30,30,30,30" into vSpacing put 4 into rootLevel end defineStruct on eraseTree global rootNode, seachPath, pathLength choose select tool drag from 0,0 to 512,342 doMenu "Clear Picture" choose field tool repeat with i = the number of card fields down to 1 click at the loc of card field i doMenu "Clear Field" end repeat put 0 into rootNode put empty into searchPath put 0 into pathLength choose browse tool end eraseTree on initPlot targetNode global searchPath, pathLength undoPlot put targetNode into line 1 of searchPath put the loc of card field id targetNode into line 2 of searchPath put 2 into pathLength set the style of card field id targetNode to shadow set the lineSize to 2 choose line tool end initPlot on termPlot set the lineSize to 1 choose browse tool end termPlot on pathPlot targetNode global searchPath, pathLength if targetNode ≠ 0 then add 1 to pathLength put targetNode into line pathLength of searchPath add 1 to pathLength put the loc of card field id targetNode into line pathLength of searchPath set the style of card field id targetNode to shadow drag from line pathLength - 2 of searchPath to line pathLength of searchPath end if end pathPlot on undoPlot global searchPath, pathLength if pathLength > 0 then choose line tool put line 1 of searchPath into targetNode set the style of card field id targetNode to rectangle put line 2 of searchPath into parentLoc put 3 into pathIndex repeat while pathIndex < pathLength put line pathIndex of searchPath into targetNode add 1 to pathIndex get line pathIndex of searchPath add 1 to pathIndex set the style of card field id targetNode to rectangle set the lineSize to 2 drag from parentLoc to it with optionKey set the lineSize to 1 drag from parentLoc to it put it into parentLoc end repeat put empty into searchPath put 0 into pathLength choose browse tool end if end undoPlot function searchTree key global rootNode, rootLevel global parentSide, parentNode, parentLevel, targetNode put 0 into parentSide put 0 into parentNode put rootLevel + 1 into parentLevel if rootNode = 0 then put 0 into targetNode return "missing" else initPlot rootNode if key = line 1 of card field id rootNode then put rootNode into targetNode return "found" end if end if put rootNode into parentNode put rootLevel into parentLevel put 0 into targetNode repeat while true get line 1 of card field id parentNode if key < it then put 2 into parentSide get line 2 of card field id parentNode if it ≠ 0 then pathPlot it if key = line 1 of card field id it then put it into targetNode return "found" else put it into parentNode subtract 1 from parentLevel end if else return "missing" end if else if key > it then put 3 into parentSide get line 3 of card field id parentNode if it ≠ 0 then pathPlot it if key = line 1 of card field id it then put it into targetNode return "found" else put it into parentNode subtract 1 from parentLevel end if else return "missing" end if end if end if end repeat end searchTree function newNode nodeLoc global rootRect choose field tool doMenu "New Field" get the number of card fields get the id of card field it set the rect of card field id it to rootRect set the loc of card field id it to nodeLoc set the style of card field id it to rectangle set the textFont of card field id it to geneva set the textSize of card field id it to 9 set the textAlign of card field id it to center set the lockText of card field id it to true put 0 into line 2 of card field id it put 0 into line 3 of card field id it return it end newNode function getNodeLoc parentSide, parentNode, parentLevel global rootLoc, hSpacing, vSpacing if parentNode = 0 then return rootLoc else put the loc of card field id parentNode into nodeLoc get item parentLevel of vSpacing add it to item 2 of nodeLoc get item parentLevel of hSpacing if parentSide = 2 then subtract it from item 1 of nodeLoc else add it to item 1 of nodeLoc end if return nodeLoc end if end getNodeLoc function makeNode parentSide, parentNode, parentLevel global rootLoc if parentNode = 0 then get newNode( rootLoc ) initPlot it return it else put getNodeLoc( parentSide, parentNode, parentLevel ) into nodeLoc get newNode( nodeLoc ) put it into line parentSide of card field id parentNode choose line tool pathPlot it return it end if end makeNode function insertNode key global rootNode, parentSide, parentNode, parentLevel get searchTree( key ) if it = "found" then termPlot return "duplicate" end if if parentLevel = 0 then termPlot return "full" end if put makeNode( parentSide, parentNode, parentLevel ) into theNode put key into line 1 of card field id theNode if parentNode = 0 then put theNode into rootNode termPlot return "inserted" end insertNode on moveSubTree parentSide, parentNode, parentLevel, nextNode if nextNode ≠ 0 then put the loc of card field id nextNode into oldLoc put getNodeLoc( parentSide, parentNode, parentLevel ) into newLoc set the loc of card field id nextNode to newLoc get line 2 of card field id nextNode if it ≠ 0 then drag from oldLoc to the loc of card field id it with optionKey moveSubTree 2, nextNode, parentLevel - 1, it end if get line 3 of card field id nextNode if it ≠ 0 then drag from oldLoc to the loc of card field id it with optionKey moveSubTree 3, nextNode, parentLevel - 1, it end if if parentNode ≠ 0 then drag from the loc of card field id parentNode to newLoc end if end if end moveSubTree function removeNode parentSide, parentNode, parentLevel, targetNode global rootNode put line 1 of card field id targetNode into key if line 2 of card field id targetNode = 0 then put line 3 of card field id targetNode into nextNode else put line 2 of card field id targetNode into nextNode end if choose line tool if parentNode ≠ 0 then drag from the loc of card field id parentNode to the loc of card field id targetNode with optionKey set the lineSize to 1 end if if nextNode ≠ 0 then drag from the loc of card field id targetNode to the loc of card field id nextNode with optionKey end if choose field tool click at the loc of card field id targetNode doMenu "Clear Field" if parentNode ≠ 0 then put nextNode into line parentSide of card field id parentNode end if if targetNode = rootNode then put nextNode into rootNode choose line tool moveSubTree parentSide, parentNode, parentLevel, nextNode return key end removeNode on findNext global parentSide, parentNode, parentLevel, targetNode put "Looking for the successor to node" && line 1 of card field id targetNode into message put 3 into parentSide put targetNode into parentNode subtract 1 from parentLevel put line 3 of card field id parentNode into targetNode pathPlot targetNode get line 2 of card field id targetNode repeat while it ≠ 0 put 2 into parentSide put targetNode into parentNode subtract 1 from parentLevel put it into targetNode pathPlot it get line 2 of card field id targetNode end repeat end findNext function deleteNode key global parentSide, parentNode, parentLevel, targetNode, pathLength get searchTree( key ) if it = "missing" then termPlot return it end if if line 2 of card field id targetNode = 0 or line 3 of card field id targetNode = 0 then get removeNode( parentSide, parentNode, parentLevel, targetNode ) else put targetNode into oldTargetNode findNext get removeNode( parentSide, parentNode, parentLevel, targetNode ) put it into line 1 of card field id oldTargetNode end if subtract 2 from pathLength termPlot return "deleted" end deleteNode on traverseTree theNode global listLine if theNode ≠ 0 then traverseTree line 2 of card field id theNode add 1 to listLine put line 1 of card field id theNode into line listLine of field treeList traverseTree line 3 of card field id theNode end if end traverseTree on makeSubTree parentNode, parentLevel if parentLevel > 0 then get makeNode( 2, parentNode, parentLevel ) makeSubTree it, parentLevel - 1 get makeNode( 3, parentNode, parentLevel ) makeSubTree it, parentLevel - 1 end if end makeSubTree on enumTree global rootLoc, rootLevel, rootNode put newNode( rootLoc ) into rootNode makeSubTree rootNode, rootLevel choose browse tool end enumTree on newTree eraseTree put empty into field treeList put "The tree is empty" into message end newTree function sideName parentSide if parentSide = 2 then return "left" else return "right" end if end sideName on findNode global parentSide, parentNode, parentLevel, targetNode ask "3 digit search key?" put it into key get searchTree( key ) termPlot if it = "found" then put "Node" && key && "found" into message else if parentNode = 0 then put "The tree is empty" into message else put "Node" && key && "missing" && sideName( parentSide ) && "of node" && line 1 of card field id parentNode into message end if end if choose browse tool end findNode on putInNode global parentSide, parentNode, parentLevel, targetNode ask "3 digit node key?" put it into key get insertNode( key ) if it = "duplicate" then put "Node" && key && "already exists" into message else if it = "full" then put "No room to insert node" && key && sideName( parentSide ) && "of node" && line 1 of card field id parentNode into message else put empty into field treeList if parentNode = 0 then put "Node" && key && "inserted as the root node" into message else put "Node" && key && "inserted" && sideName( parentSide ) && "of node" && line 1 of card field id parentNode into message end if end if end if choose browse tool end putInNode on takeAwayNode global parentSide, parentNode, parentLevel, targetNode ask "3 digit node key?" put it into key get deleteNode( key ) if it = "missing" then if parentNode = 0 then put "The tree is empty" into message else put "Node" && key && "missing" && sideName( parentSide ) && "of node" && line 1 of card field id parentNode into message end if else put empty into field treeList put "Node" && key && "deleted from the tree" into message end if choose browse tool end takeAwayNode on walkTree global rootNode, listLine undoPlot put empty into field treeList put 0 into listLine traverseTree rootNode if listLine = 0 then put "The tree is empty" into message else if listLine = 1 then put "There is only the root node in the tree" into message else put "There are" && listLine && "nodes in the tree" into message end if end if end walkTree